<m-api-data-table
  [dataSource]="dataSource"
  [selection]="selection"
  [searchControl]="searchControl"
  #tableRef
>
  <ng-container mDataTableColumn header="终端别名">
    <ng-template let-name="name">
      <td>{{ name }}</td>
    </ng-template>
  </ng-container>
  <ng-container mDataTableColumn header="状态">
    <ng-template let-status="status">
      <td><m-enable-status-text [status]="status"></m-enable-status-text></td>
    </ng-template>
  </ng-container>
  <ng-container mDataTableColumn header="系统更新">
    <ng-template let-update="need_upgrade">
      <td><m-update-status-text [status]="update"></m-update-status-text></td>
    </ng-template>
  </ng-container>
  <ng-container mDataTableColumn header="在线">
    <ng-template let-online="online">
      <td><m-online-status-text [status]="online"></m-online-status-text></td>
    </ng-template>
  </ng-container>
  <ng-container mDataTableColumn header="操作">
    <ng-template let-id="pc_id" let-name="name" let-status="status">
      <td>
        <button mat-icon-button [matMenuTriggerFor]="editMenuRef">
          <mat-icon>edit</mat-icon>
        </button>
        <mat-menu #editMenuRef>
          <!-- <button mat-menu-item>定制权限</button> -->
          <button mat-menu-item (click)="tableRef.refresh(upgrade(id))">更新系统</button>
          <button mat-menu-item [mDetailRouterLink]="{ id: id, type: 'computer', name: name }">
            查看终端信息
          </button>
          <button
            mat-menu-item
            (click)="tableRef.refresh(disable(id))"
            *ngIf="status === EnableStatus.Enable"
          >
            停用
          </button>
          <button
            mat-menu-item
            (click)="tableRef.refresh(enable(id))"
            *ngIf="status === EnableStatus.Disable"
          >
            启用
          </button>
          <button mat-menu-item [style.color]="'red'" (click)="tableRef.refresh(delete(id))">
            移除终端
          </button>
        </mat-menu>
      </td>
    </ng-template>
  </ng-container>
  <button class="btn btn-secondary btn-sm mr-3" (click)="tableRef.selectAll()">全选</button>
  <button class="btn btn-secondary btn-sm" [matMenuTriggerFor]="editMenuRef">
    批量操作
  </button>
  <mat-menu #editMenuRef>
    <!-- <button mat-menu-item>定制权限</button> -->
    <button mat-menu-item (click)="tableRef.refresh(upgrade())">更新系统</button>
    <button mat-menu-item (click)="tableRef.refresh(disable())">停用</button>
    <button mat-menu-item (click)="tableRef.refresh(enable())">启用</button>
    <button mat-menu-item [style.color]="'red'" (click)="tableRef.refresh(delete())">
      移除终端
    </button>
  </mat-menu>
</m-api-data-table>
